package com.kuangstudy.controller.params;

import com.kuangstudy.utils.fn.asserts.Vsserts;
import com.kuangstudy.vo.ParamsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * Author: yykk Administrator
 * Version: 1.0
 * Create Date Time: 2021/12/13 20:17.
 * Update Date Time:
 *
 * @see
 */

@RestController
@Slf4j
public class PararmeterController {

    @GetMapping("/param1")
    public String params1(String id, String name) {
        log.info("我的参数是：id:"+id+",名字是："+name);
        log.info("我的参数是：id:{},名字是：{}",id,name);
        // 校验
        Vsserts.isEmptyEx(id, new RuntimeException("请输入ID!!!"));
        Vsserts.isEmptyEx(name, new RuntimeException("请输入名字!!!"));
        // 给默认值
        Vsserts.isEmptyDefault(id,"");
        Vsserts.isEmptyDefault(name,"");
        log.info("你输入的id是:{},name是：{}",id,name);

        return "success";
    }

    @GetMapping("/param3")
    public String param3(@RequestParam(value = "id",required = false) String id,
                         @RequestParam(value = "name",required = false) String name) {
        log.info("你输入的id是:{},name是：{}",id,name);
        return "success";
    }


    @GetMapping("/param4")
    public String param4(@RequestParam(value = "id") String id, String name) {
        log.info("你输入的id是:{},name是：{}",id,name);
        return "success";
    }

    @GetMapping("/param5")
    public String param5(ParamsVo paramsVo) {
        log.info("你传递的参数是：{}",paramsVo);
        return "success";
    }


    @GetMapping("/param2")
    public String params2(@RequestParam(value = "id",defaultValue = "") String id,
                          @RequestParam(value = "name",defaultValue = "") String name) {
        log.info("你输入的id是:{},name是：{}",id,name);
        return "success";
    }


    @PostMapping("/param6")
    public String param6(@RequestBody  ParamsVo paramsVo) {
        log.info("你传递的参数是：{}",paramsVo);
        return "success";
    }


}
